package com.brid.controller;

import com.brid.dto.UserDTO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.testng.annotations.Test;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;


/**
 * @Author: sijunqiang
 * @Date: 2020/4/23 17:43
 * @Description:
 */
@RestController
@RequestMapping(value = "/controller", produces = MediaType.APPLICATION_JSON_VALUE)
@Slf4j
public class JsonController {

    @ApiOperation(value = "测试使用@jsonIgnore 忽略响应的字段值")
    @GetMapping(value = "/json", consumes = MediaType.APPLICATION_JSON_VALUE)
    public UserDTO testJsonIgnore() {
        UserDTO user = new UserDTO();
        user.setAddress("shanghai");
        user.setName("sijunqiang");
        user.setSex("man");
        user.setAge(25);
        return user;
    }


    @GetMapping(value = "/notEmpty")
    public String testNotEmpty(@RequestParam(value = "name" ) @Valid @NotBlank(message = "name: can be not empty") String name) {
        log.info("name:[{}]", name);
        return name;
    }





}
